import requests,json

# 地理编码，不用修改
def geocode(key,address,city=None,batch="false",sig=None,output="json",callback=None):
    """地理编码"""
    url = "https://restapi.amap.com/v3/geocode/geo?parameters"
    params = {
    "key":key,
    "address":address,
    "city":city,
    "batch":batch,
    "sig":sig,
    "output":output,
    "callback":callback
    }
    r = requests.get(url,params)
    results = r.json()
    return results

# 骑行
def bicycling(key,origin,destination):
    """骑行"""
    bicycling_url = "https://restapi.amap.com/v4/direction/bicycling?parameters"
    params = {
        "key":key,
        "origin":origin,
        "destination":destination
    }
    r = requests.get(bicycling_url,params)
    results=r.json()
    return results

# 步行路径规划函数
def walking(key,origin,destination):
    """步行路径规划"""
    walking_url = "https://restapi.amap.com/v3/direction/walking?parameters"
    params = {
        'key':key,
        'origin':origin,# 起点（经纬度信息）
        'destination':destination,# 终点（经纬度信息）
    }
    r = requests.get(walking_url,params)
    results = r.json()
    return results

# 驾车路径规划函数
def driving(key,origin,destination):
    """驾车路径规划"""
    driving_url = "https://restapi.amap.com/v3/direction/driving?parameters"
    params = {
        'key':key,
        'origin':origin,# 起点
        'destination':destination,# 终点
        'strategy':10,# 路径策略
        'waypoints':None,# 需要途经的地点
        'avoidpolygons':None,# 避让区域
    }
    r = requests.get(driving_url, params)
    results = r.json()
    return results

#公交路径规划查询
def bus(key,origin,destination):
    """公交路径规划"""
    bus_url = "https://restapi.amap.com/v3/direction/transit/integrated?parameters"
    params = {
        'key':key,
        'origin':origin,# 起点 （经纬度）
        'destination':destination,# 终点（经纬度）
        'city':'010',# 公交查询所在城市
        'cityd':None,# 跨城公交选填
        'extensions':'base',# 返回结果详情
        'strategy':0,# 换成策略0：最快捷模式1：最经济模式2：最少换乘模式3：最少步行模式5：不乘地铁模式
        'nightflag':0,# 是否记夜班车
        'date':None,# 发车日期
        'time':None,# 发车时间
        'output':'json'
    }
    r = requests.get(bus_url, params)
    results = r.json()
    return results